package cn.jcet.mapreduce.sort2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/11 23:16
 */
public class FlowMapper2 extends Mapper<LongWritable,Text,Text,FlowBean2> {

    private Text k = new Text();
    private FlowBean2 v = new FlowBean2();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();

        String[] fileds = line.split("\t");

        String phoneNum = fileds[1];

        long upFlow = Long.parseLong(fileds[fileds.length - 3]);
        long downFlow = Long.parseLong(fileds[fileds.length - 2]);

        v.setUpFlow(upFlow);
        v.setDownFlow(downFlow);

        k.set(phoneNum);

        context.write(k,v);
    }
}
